import request from '@/utils/request';

export interface PartyMember {
  id: number;
  className: string;
  position: string;
  name: string;
  idCard: string;
  identifier: string;
  joinDate: string;
  positionLevel: string;
  createTime: string;
  updateTime: string;
}

export interface PartyMemberQueryParams {
  current: number;
  size: number;
  keyword?: string;
  className?: string;
  position?: string;
  positionLevel?: string;
}

export interface PartyMemberQueryResult {
  records: PartyMember[];
  total: number;
  size: number;
  current: number;
}

export interface PartyMemberDTO {
  className: string;
  position: string;
  name: string;
  idCard: string;
  identifier: string;
  joinDate: string;
  positionLevel: string;
}

export interface ImportError {
  row: number;
  field: string;
  message: string;
}

// 获取党员列表
export const getPartyMemberList = (params: PartyMemberQueryParams) => {
  return request.get<PartyMemberQueryResult>('/party-members', { params });
};

// 获取党员详情
export const getPartyMember = (id: number) => {
  return request.get<PartyMember>(`/party-members/${id}`);
};

// 创建党员
export const createPartyMember = (data: PartyMemberDTO) => {
  return request.post<void>('/party-members', data);
};

// 更新党员
export const updatePartyMember = (id: number, data: PartyMemberDTO) => {
  return request.put<void>(`/party-members/${id}`, data);
};

// 删除党员
export const deletePartyMember = (id: number) => {
  return request.delete<void>(`/party-members/${id}`);
};

// 导入党员数据
export const importPartyMembers = (file: File) => {
  const formData = new FormData();
  formData.append('file', file);
  return request.post<string[]>('/party-members/import', formData, {
    headers: {
      'Content-Type': 'multipart/form-data',
    },
  });
};

// 导出党员数据
export const exportPartyMembers = (params: PartyMemberQueryParams) => {
  return request.get('/party-members/export', {
    params,
    responseType: 'blob',
  });
}; 